'''
Created on 17 janv. 2013

@author: rouis
'''
import random
import os.path
'''Check if the word is in the dictionnary or not
   return true or false'''

dictionary = os.path.dirname(__file__) + '/anglais.txt'   

class Dict:
    def __init__(self):
        self.dict = dictionary
        
    def validWordKo(self,word):  
        word = word.lower()
        readline = open(dictionary, 'r')
        if word in readline.read():
            readline.close()
            return True
        return False
    
    def validWord(self,word):  
        word = word.lower()
        content = open(dictionary, 'r')        
        for line in content:          
            if word == line.strip('\n'):
                return True                               
        return False
    
    '''get a random word from the dictionary'''
    def getWord(self):
        words = [line.strip() for line in open(dictionary)]
        return random.choice(words)

    '''get a random word with a length <= 5 from the dictionary'''    
    def getShortWord(self):
        dico = [line.strip() for line in open(dictionary)]
        words =[]
        for word in dico:
            if(len(word) <= 5):
                words.append(word)
        return random.choice(words)


d = Dict()
#print " a word with 5 letters : " , getShortWord()
print"valid? ", d.validWord("oo")



        
    